﻿'ACTUALIZAR EL GRID DE HISTORIAL DE EXAMENS CUANDO SE AGREGA EXAMENES AL FORMULARIO
Imports System.Windows.Forms
Imports CapaNegocio
Public Class frmGestionarExamen

    Public Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Integer, ByVal bRevert As Integer) As Integer
    Public Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
    Public Const SC_CLOSE = &HF060&
    Public Const MF_BYCOMMAND = &H0&
    Function RemoveXButton(ByVal iHWND As Integer) As Integer
        Dim iSysMenu As Integer
        iSysMenu = GetSystemMenu(iHWND, False)
        Return RemoveMenu(iSysMenu, SC_CLOSE, MF_BYCOMMAND)
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbuscar.Click
        busquedapaciente()
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAgregarExamen.Click
        'listar examen
        focusfrm = True
        lexamenglobal.Show()
        lexamenglobal.Focus()
        lexamenglobal.Visible = True
    End Sub
    Private Sub frmGestionarExamen_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
        RefrescarDGV()        
    End Sub
    Private Sub frmGestionarExamen_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Enter
        RefrescarDGV()
    End Sub
    Private Sub frmGestionarExamen_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        frmtest = False
    End Sub
    Private Sub frmGestionarExamen_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Me.Visible = False
        frmtest = False
    End Sub
    Private Sub frmGestionarExamen_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.GotFocus
        RefrescarDGV()
    End Sub
    Private Sub frmGestionarExamen_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Deshabilitar boton [X]
        RemoveXButton(Me.Handle().ToInt32())
        lblvalidacion.Text = "VALIDACION DE GESTANTE"
        DGVPacienteExamen.Rows.Clear()
    End Sub
    Public Sub RefrescarDGV()
        cB.Paciente_codigo_paciente = cP.codigo_paciente
        With DGVPacienteExamen
            .DataSource = cB.ListarBoletas            
            .Columns(1).ReadOnly = True
            .Columns(2).ReadOnly = True
            .Columns(2).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
            .Columns(4).ReadOnly = True
            .Columns(5).ReadOnly = True
            .Columns(3).DefaultCellStyle.BackColor = Drawing.Color.Blue
            .Columns(3).DefaultCellStyle.SelectionBackColor = Drawing.Color.DeepSkyBlue
            .Columns(2).DefaultCellStyle.SelectionForeColor = Drawing.Color.Black
            .Columns(3).DefaultCellStyle.SelectionForeColor = Drawing.Color.Black
            .Columns(4).DefaultCellStyle.SelectionForeColor = Drawing.Color.Black
            .Refresh()
        End With
    End Sub
    Private Sub btnVerDetalles_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVerDetalles.Click
        Dim frmrespuesta As New frmResultadosExamen
        Dim aux As Integer = 0
        For Each Row As DataGridViewRow In DGVPacienteExamen.Rows()
            'captura la segunda columna del la lista
            If (Row.Cells(0).Value = True) Then
                aux = Row.Cells(1).Value 'CODIGO DE BOLETA
                cB.Boleta_codigo_Boleta = aux              'CODIGO DE BOLETA para EL DETALLE   
                frmrespuesta.Show()
                Exit For 'Sale del ForEACH solo recorre el for each 1 vez
            End If
        Next
    End Sub
    Private Sub btnActualizarEstado_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnActualizarEstado.Click
        Dim codigoboleta As Integer = 0
        Dim estadoboleta As Integer
        For Each Row As DataGridViewRow In DGVPacienteExamen.Rows()
            'captura la segunda columna del la lista
            If (Row.Cells(0).Value = True) Then
                codigoboleta = Row.Cells(1).Value
                estadoboleta = Row.Cells(3).Value
                cB.estado_Boleta = estadoboleta * -1
                cB.Boleta_codigo_Boleta = codigoboleta
                cB.mtdActualizarEstadoBoleta()
                Exit For 'Sale del ForEACH solo se recorre 1 vez
            End If
        Next
        RefrescarDGV()
    End Sub
    Private Sub btnImprimir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImprimir.Click
        Dim codigoboleta As Integer = 0
        Dim frmimp As New frmImprimir
        For Each Row As DataGridViewRow In DGVPacienteExamen.Rows()
            'captura la segunda columna del la lista
            If (Row.Cells(0).Value = True) Then
                codigoboleta = Row.Cells(1).Value                               
                cB.Boleta_codigo_Boleta = codigoboleta
                frmimp.Show()
                Exit For 'Sale del ForEACH solo se recorre 1 vez
            End If
        Next
       
    End Sub
    Private Sub txtdni_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtdni.KeyDown
        If e.KeyValue = 13 Then
            busquedapaciente()
        End If
    End Sub
    Private Sub busquedapaciente()

        Dim gestante As Integer
        Dim fecha As String


        cP.dni_Paciente = txtdni.Text()
        txtdni.Text = ""
        If (cP.mtdBuscarPaciente()) Then
            txtnombre.Text = cP.nombre_Paciente
            If cP.sexo_Paciente = 1 Then
                txtsexo.Text = "Masculino"
            Else
                txtsexo.Text = "Femenino"
            End If
            txtapepaterno.Text = cP.apepaterno_Paciente
            txtapematerno.Text = cP.apematerno_Paciente
            If cP.tipo_PacienteGestante = 1 Then
                txtgestante.Text = "Si"
            Else
                txtgestante.Text = "No"
            End If
            txttiposeguro.Text = cP.tiposeguro_PacienteTipo            

            If cP.fecha_PacienteGestante = "0000-00-00" Then
                txtultimaatencion.Text = "NO HAY ULTIMA FECHA"
            Else
                txtultimaatencion.Text = cP.fecha_PacienteGestante
            End If


            'Encuentra paciente y habilita estos botones
            'validacion de gestante
            If cP.mtdValidacionGestante() Then
                gestante = cP.tipo_PacienteGestante
                fecha = cP.fecha_PacienteGestante
                'lblvalidacion.Text = "ES UN PACIENTE NORMAL"
                'MsgBox(fecha)
                If gestante = 0 And fecha = "0000-00-00" Then
                    lblvalidacion.Text = "PACIENTE NO GESTANTE"
                    lblvalidacion.ForeColor = Drawing.Color.Green
                ElseIf gestante = 1 And fecha = "0000-00-00" Then
                    lblvalidacion.Text = "PACIENTE GESTANTE PRIMERA VEZ"
                    lblvalidacion.ForeColor = Drawing.Color.Orange
                ElseIf gestante = 1 Then
                    lblvalidacion.Text = "PACIENTE GESTANTE MAS DE PRIMERA VEZ"
                    lblvalidacion.ForeColor = Drawing.Color.Red
                End If
            End If

            activarbotones()

            DGVPacienteExamen.Visible = True
            RefrescarDGV()
        End If
    End Sub
    Private Sub activarbotones()
        btnAgregarExamen.Enabled = True
        btnVerDetalles.Enabled = True
        btnActualizarEstado.Enabled = True
        btnImprimir.Enabled = True
    End Sub
    Private Sub desactivarbotones()
        btnAgregarExamen.Enabled = False
        btnVerDetalles.Enabled = False
        btnActualizarEstado.Enabled = False
        btnImprimir.Enabled = False
    End Sub
    Private Sub btnCerrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCerrar.Click
        DGVPacienteExamen.Visible = False
        Me.Visible = False
        frmtest = False
    End Sub
    Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If frmpatient = False Then
            Dim frmp As New frmPaciente
            frmp.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedToolWindow
            frmp.Show()
        End If
    End Sub

    Private Sub txtdni_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtdni.KeyPress
        'Validacion -> Ingreso de datos SOLO NUMEROS
        If Char.IsDigit(e.KeyChar) Then
            e.Handled = False
        ElseIf Char.IsControl(e.KeyChar) Then
            e.Handled = False
        Else
            e.Handled = True
        End If
    End Sub

    
End Class